﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YellowMap
{
    public class GoogleDirectionRequest
    {

        const string baseURL = "http://maps.googleapis.com/maps/api/directions/json?origin={0}&destination={1}&sensor=false&language={2}&units={3}&mode={4}";
        

        static GoogleDirectionRequest()
        {
            ApiKey = "AIzaSyAo3PYOTkQVXbn_Xz-v0OMuDH89YAhjSd8";
        }

        public GoogleDirectionRequest()
        {
            Unit = DistanceUnit.Km;
            Language = DisplayLanguage.ENGLISH;
            Mode = TravelMode.Driving;
        }

        /// <summary>
        /// Your application's API key. This key identifies your application for purposes of quota management and so that Places added from your application are made immediately available to your app.
        /// </summary>
        public static string ApiKey { get; set; }

        public override string ToString()
        {
            convertEnumtoString();
            return String.Format(baseURL, origin, destination, language, unit, mode);
        }
        
        public void SetStartEnd(string fromAddress, string toAddress)
        {
            origin = System.Net.WebUtility.UrlEncode(fromAddress);
            destination = System.Net.WebUtility.UrlEncode(toAddress);
        }

        public void SetStartEnd(string fromAddress, double toLat, double toLng)
        {
            origin = System.Net.WebUtility.UrlEncode(fromAddress);
            destination = toLat + "," + toLng;
        }

        public void SetStartEnd(double fromLat, double fromLng, string toAddress)
        {
            origin = fromLat + "," + fromLng;
            destination = System.Net.WebUtility.UrlEncode(toAddress);
        }

        public void SetStartEnd(double fromLat, double fromLng, double toLat, double toLng)
        {
            origin = fromLat + "," + fromLng;
            destination = toLat + "," + toLng;
        }

        void convertEnumtoString()
        {
            #region mode
            switch (Mode)
            {
                case TravelMode.Driving:
                    mode = "driving";
                    break;
                case TravelMode.Walking:
                    mode = "waking";
                    break;
                case TravelMode.Bicycling:
                    mode = "bicycling";
                    break;
                case TravelMode.Transit:
                    mode = "transit";
                    break;
                default:
                    break;
            } 
            #endregion

            #region language
            switch (Language)
            {
                case DisplayLanguage.GERMAN: language = "de";
                    break;
                case DisplayLanguage.ENGLISH: language = "en";
                    break;
                case DisplayLanguage.FRENCH: language = "fr";
                    break;
                case DisplayLanguage.HUNGARIAN: language = "hu";
                    break;
                case DisplayLanguage.INDONESIAN: language = "id";
                    break;
                case DisplayLanguage.ITALIAN: language = "it";
                    break;
                case DisplayLanguage.JAPANESE: language = "ja";
                    break;
                case DisplayLanguage.KOREAN: language = "ko";
                    break;
                case DisplayLanguage.DUTCH: language = "nl";
                    break;
                case DisplayLanguage.RUSSIAN: language = "ru";
                    break;
                case DisplayLanguage.SWEDISH: language = "sv";
                    break;
                case DisplayLanguage.THAI: language = "th";
                    break;
                case DisplayLanguage.VIETNAMESE: language = "vi";
                    break;
                case DisplayLanguage.CHINESE: language = "zh-TW";
                    break;
                default:
                    break;
            } 
            #endregion

            #region unit
            switch (Unit)
            {
                case DistanceUnit.Km: unit = "metric";
                    break;
                case DistanceUnit.Mile: unit = "imperial";
                    break;
                default:
                    break;
            } 
            #endregion
        
        }

        string mode, unit, language, origin, destination;

        public TravelMode Mode { get; set; }

        public DistanceUnit Unit { get; set; }

        public DisplayLanguage Language { get; set; }

        public enum DisplayLanguage
        {
            GERMAN, ENGLISH, FRENCH, HUNGARIAN, INDONESIAN, ITALIAN, JAPANESE, KOREAN, DUTCH, RUSSIAN, SWEDISH, THAI, VIETNAMESE, CHINESE 
        }

        public enum DistanceUnit
        { 
            Km, Mile
        }

        public enum TravelMode
        {
            Driving, Walking, Bicycling, Transit 
        }



    }
}
